<template>
    <div class="conter">
        <el-card class="box-card">
            <!-- 设备分类列表 -->
            <div class="out">
                <div class="header-box">
                    <el-button icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['equipment:EquipmentParameter:add']">新增</el-button>
                    <el-button icon="el-icon-edit" size="mini" @click="handleUpdate" :disabled="single"
                        v-hasPermi="['equipment:EquipmentParameter:edit']">修改</el-button>
                    <el-button icon="el-icon-tickets" size="mini" v-hasPermi="['equipment:EquipmentParameter:view']">查看
                    </el-button>
                    <el-button icon="el-icon-delete" size="mini" @click="handleDelete" :disabled="multiple"
                        v-hasPermi="['equipment:EquipmentParameter:remove']">删除</el-button>
                </div>
                <div class="right">
                    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                        label-width="68px">
                        <el-form-item label="设备编号" prop="d_id">
                            <el-input v-model="queryParams.d_id" placeholder="设备编号" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
                        <el-form-item label="设备名称" prop="d_name">
                            <el-input v-model="queryParams.postName" placeholder="设备名称" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
                        <!-- <el-form-item label="状态" prop="state">
                            <el-select v-model="queryParams.state" placeholder="设备状态" clearable>
                                <el-option v-for="item in cateList" :key="item.id" :label="item.state"
                                    />
                            </el-select>
                        </el-form-item> -->
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
                            </el-button>
                            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
            <!-- 设备分类表格 -->
            <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column label="序号" align="center" prop="id" />
                <el-table-column label="设备图片" align="center" prop="d_image" />
                <el-table-column label="设备编号" align="center" prop="d_id" />
                <el-table-column label="设备名称" align="center" prop="d_name" />
                <el-table-column label="设备型号" align="center" prop="d_model" />
                <el-table-column label="设备品牌" align="center" prop="d_brand" />
                <el-table-column label="设备类别" align="center" prop="d_type" />
                <el-table-column label="资产部门" align="center" prop="d_departme" />
                <el-table-column label="存放位置" align="center" prop="d_place" />
                <el-table-column label="设备状态" align="center" prop="state" width="100" />

            </el-table>
            <!-- 分页 -->
            <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </el-card>
        <!-- 增加或者修改 -->
        <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules">
                <el-row :gutter="80">
                    <!-- <el-col :span="8">
                        <el-form-item label="设备图片" prop="d_image" :label-width="formLabelWidth">
                            <el-input v-model="form.postName" placeholder="请输入岗位名称" />
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="8">
                        <el-form-item label="设备编号" prop="d_id" :label-width="formLabelWidth">
                            <el-input v-model="form.d_id" placeholder="请输入编号" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="设备名称" prop="d_name" :label-width="formLabelWidth">
                            <el-input v-model="form.d_name" placeholder="请输入名称" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="设备品牌" prop="d_brand" :label-width="formLabelWidth">
                            <el-input v-model="form.d_brand" placeholder="请输入品牌名称" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="设备类别" prop="d_type" :label-width="formLabelWidth">
                            <el-input v-model="form.d_type" placeholder="请输入设备类别" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="资产部门" prop="d_departme" :label-width="formLabelWidth">
                            <el-input v-model="form.d_departme" placeholder="请输入资产部门名称" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="存放位置" prop="d_place" :label-width="formLabelWidth">
                            <el-input v-model="form.d_place" placeholder="请输入存放位置" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="设备状态" prop="state">
                            <el-select v-model="form.state" placeholder="请选择状态" size="small">
                            <el-option label="正常" value="正常"></el-option>
                            <el-option label="已发布" value="已发布"></el-option>
                        </el-select>
                        </el-form-item>
                    </el-col>

                </el-row>
                <!-- 设备图片 -->
                <el-form-item label="设备图片" prop="d_image">
                    <!-- 文件选择框，默认被隐藏 -->
                    <input type="file" style="display: none;" accept="image/*" ref="iptFileRef"
                        @change="onCoverChangeFn" />
                    <!-- 选择封面的按钮 -->
                    <el-button type="text" @click="chooseImgFn">+ 上传封面</el-button>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
  
<script>
export default {
    name: 'EquipmentParameter',
    data() {
        return {
            //遮罩层
            loading: true,
            // 总条数
            total: 0,
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            //状态存放数据
            radio: '1',

            // 选中数组
            ids: [],
            // 弹出层标题
            title: "",
            //状态对象
            state: {},
            //新增输入框大小
            formLabelWidth: '120px',
            //查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                d_id: undefined,
                d_name: undefined,
            },
            // 是否显示弹出层
            open: false,
            //显示搜索条件
            showSearch: true,
            //表单参数
            form: {},
            // 岗位表格数据
            postList: [],
            rules: {
                d_id: [
                    { required: true, message: "设备编号不能为空", trigger: "blur" }
                ],
                d_name: [
                    { required: true, message: "设备名称不能为空", trigger: "blur" }
                ],
                d_departme: [
                    { required: true, message: "资产部门不能为空", trigger: "blur" }
                ]
            }
        }
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询岗位列表 */
        getList() {
            this.loading = true;
            listPost(this.queryParams).then(response => {
                this.postList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: undefined,
                d_image: undefined,
                d_id: undefined,
                d_name: undefined,
                d_model: undefined,
                d_brand: undefined,
                d_type: undefined,
                d_departme: undefined,
                d_place: undefined,
                d_state: '0'
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            //   this.reset();
            this.open = true;
            this.title = "添加岗位";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            //   this.reset();
            const id = row.id || this.ids
            getPost(id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改岗位";
            });
        },

        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != undefined) {
                        // updatePost(this.form).then(response => {
                        //     this.$modal.msgSuccess("修改成功");
                        //     this.open = false;
                        //     this.getList();
                        // });
                    } else {
                        console.log(this.form);
                        // addPost(this.form).then(response => {
                        //     this.$modal.msgSuccess("新增成功");
                        //     this.open = false;
                        //     this.getList();
                        // });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const postIds = row.id || this.ids;
            this.$modal.confirm('是否确认删除岗位编号为"' + postIds + '"的数据项？').then(function () {
                return delPost(postIds);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 上传图片 */
        onCoverChangeFn() {
            console.log(11);
        },
        chooseImgFn() {
            console.log(111);
        }
    }
}
</script>
  
<style lang="scss" scoped>
.conter {
    padding: 10px;
}

.out {
    display: flex;

}

.header-box {
    width: 500px;
}

.right {
    flex: 1;
}

.el-table {
    margin-top: 10px
}
</style>